
import 'package:flutter/material.dart';
import '../../utils/Global.dart';
import 'package:provider/provider.dart';
import '../../provider/UserProvider.dart';
import '../../provider/CurrentIndexProvider.dart';
class Mine extends StatefulWidget {
  const Mine({Key? key}):super(key: key);

  @override
  State<Mine> createState() => _MineState();
}

class _MineState extends State<Mine> {
  
  @override
  Widget build(BuildContext context) {
    double iconSize = 24.0;
    double arrowSize = 16.0;
    TextStyle ts1 = TextStyle(fontSize: 26);
    TextStyle ts2 = TextStyle(fontSize: 16, color: Colors.grey[600]);
    /// 垂直方向的分割线
    SizedBox vline = SizedBox(
      width: 1,
      height: 60,
      child: DecoratedBox(
        decoration: BoxDecoration(color: Colors.grey[300])
      )
    );
    UserProvider userProvider = Provider.of<UserProvider>(context);
    return SingleChildScrollView(

      child: Container(
        child: Column(
          children: [
            Card(
              margin: EdgeInsets.all(16),
              shadowColor: Colors.black12,
              elevation: 10, // 阴影高度
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(10),
                // side: BorderSide(
                //   color: 
                // )
              ),
              child: Column(
                children: [
                  ListTile(
                    leading: userProvider.userInfo['portrait'] == null
                    ?
                    Icon(
                      Icons.supervised_user_circle_rounded,
                      size: 50
                    )
                    :
                    Image.network(
                      userProvider.userInfo['portrait'] ?? '',
                      fit: BoxFit.cover
                    ),
                    
                    title: Text(
                      userProvider.userInfo['username'] ?? '',
                      style: TextStyle(
                        fontSize: 24
                      ),
                    ),
                    subtitle: InkWell(
                      child: Text(
                        "编辑个人资料",
                        style: TextStyle(
                          fontSize: 16
                        ),
                      ),
                      onTap: () {
                        G.router?.navigateTo(context, '/profile');
                      }
                    )
                  ),
                  const Divider(),
                  Container(
                    margin: EdgeInsets.all(10),
                    padding: EdgeInsets.all(10),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: [
                        Column(
                          children: [
                            Text('14:06', style: ts1),
                            Text('学习时长', style: ts2)
                          ]
                        ),
                        vline,
                        Column(
                          children: [
                            Text('2', style: ts1),
                            Text('优惠券', style: ts2)
                          ]
                        ),
                        vline,
                        Column(
                          children: [
                            Text('75', style: ts1),
                            Text('学分', style: ts2)
                          ]
                        )
                      ],
                    )
                  )
                ]
              ),
            ),
            ListTile(
              leading: Padding(
                padding: const EdgeInsets.all(0.0), // 根据需求设置内边距
                child: Icon(Icons.settings, size: iconSize,),
              ),
              // contentPadding: EdgeInsets.fromLTRB(16.0, 0, 16.0, 0),
              contentPadding: EdgeInsets.fromLTRB(16.0, 0, 16.0, 0),
              title: const Text('设置', style: TextStyle(fontSize: 16)),
               trailing: Icon(Icons.arrow_forward_ios, size: arrowSize),
            ),
            ListTile(
              leading: Padding(
                padding: const EdgeInsets.all(0.0), // 根据需求设置内边距
                child: Icon(Icons.help_outline, size: iconSize,),
              ),
              contentPadding: EdgeInsets.fromLTRB(16.0, 0, 16.0, 0),
              title: const Text('帮助与反馈', style: TextStyle(fontSize: 16)),
               trailing: Icon(Icons.arrow_forward_ios, size: arrowSize),
            ),
            ListTile(
              leading: Padding(
                padding: const EdgeInsets.all(0.0), // 根据需求设置内边距
                child: Icon(Icons.info_outline, size: iconSize,),
              ),
              contentPadding: EdgeInsets.fromLTRB(16.0, 0, 16.0, 0),
              title: const Text('关于', style: TextStyle(fontSize: 16)),
               trailing: Icon(Icons.arrow_forward_ios, size: arrowSize),
            ),
            ListTile(
              leading: Padding(
                padding: const EdgeInsets.all(0.0), // 根据需求设置内边距
                child: Icon(Icons.logout_outlined, size: iconSize,),
              ),
              contentPadding: EdgeInsets.fromLTRB(16.0, 0, 16.0, 0),
              title: const Text('退出', style: TextStyle(fontSize: 16)),
              trailing: Icon(Icons.arrow_forward_ios, size: arrowSize),
              onTap: () async {
              var res = await G.api.user.logout();
              if (res == true) {
                // 更改用户状态
                userProvider.doLogout();
                // 跳转到 用户登录页
                G.router?.navigateTo(context, '/login');
                // context.read<CurrentIndexProvider>().changeIndex(0);
                // Navigator.popUntil(context, ModalRoute.withName('/'));

                return;
              }
            },
            ),
           
            // Text(userProvider.userInfo['username'] ?? ''),
            // ElevatedButton(
            //   onPressed: () {
            //     G.router?.navigateTo(context, '/login');
            //   },
            //   child: Text('跳转到登录')
            // )
        ]),
      ),
    );
  }  
}